﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ecdl.demo.model.expression;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Drawing;

namespace ecdl.demo.model.expression {
    public class GraphicsExistsExpression : WordExpression {
        private const string FAIL_POSITIVE = "Es konnte kein Bild gefunden werden.";
        private const string FAIL_NEGATIVE = "Das Bild konnte gefunden werden.";
        private const string SUCCESS_POSITIVE = FAIL_NEGATIVE;
        private const string SUCCESS_NEGATIVE = FAIL_POSITIVE;


        protected override ExpressionState Evaluate(IEnumerable<OpenXmlElement> contextElements) {
            //get all graphics
            var graphics = Descendents<Graphic>(contextElements);
            
            if (graphics.Count() > 0) {
                return Success(SUCCESS_POSITIVE, SUCCESS_NEGATIVE);
            } else {
                return Fail(FAIL_POSITIVE, FAIL_NEGATIVE);
            }
        }
    }

    public class GraphicsExistsExpressionDTO : ExpressionDTO {
        public GraphicsExistsExpressionDTO() :base (typeof(GraphicsExistsExpression)){
        }
    }
}
